package kr.hkit.powerjava.chapter22.work2.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import kr.hkit.powerjava.chapter22.work2.vo.Student;

public class StudentManagerImpl implements ItemDaointerface<Student> {
	private ArrayList<Student> arList;
	
	public StudentManagerImpl(ArrayList<Student>arList) {
		this.arList =arList;
		
	}


	@Override
	public void addItem(Student item) {
		arList.add(item);
		
	}

	@Override
	public void delItem(Student item) {
		arList.remove(item);
		
	}

	@Override
	public void updateItem(Student item) {
		if (searchItem(item)){
		arList.set(arList.indexOf(item),item);
		}else{
			System.out.println("수정실패");
		}
		
	}

	@Override
	public boolean searchItem(Student item) {
		return arList.contains(item);
	}

	@Override
	public void prnItems() {
		prnHeader();
		for(Student s : arList){
			System.out.println(s);
		}
		System.out.println();
	}

	private void prnHeader() {
		String str=String
		.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t",
				"학번", "성명", "국어", "영어", "수학", "총점", "평균");
		System.out.println(str);
		System.out.println("------------------------------------");
		
	}


	@Override
	public void prnItems(Comparator<Student> comp) {
		Collections.sort(arList,comp);
		prnItems();
		
	}


	

}
